﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.IsolatedStorage;
using System.IO;
using System.Diagnostics;

namespace TakePhotoTogether.Utils
{
    class Log
    {
        private static IsolatedStorageFile IsoFile = IsolatedStorageFile.GetUserStoreForApplication();
        private static DateTime timestart;

        public static void StartLog(string feature)
        {
            #if DEBUG
            if (!IsoFile.DirectoryExists("Log"))
                IsoFile.CreateDirectory("Log");

            StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Log\\log_take_photo_together.log", FileMode.OpenOrCreate, IsoFile));
            DateTime currentTime = DateTime.Now;
            Debug.WriteLine("[{0}] start {1} {2} {3}", feature, currentTime.ToShortDateString(), currentTime.ToLongTimeString(), currentTime.Millisecond);
            sw.WriteLine("[{0}] start {1} {2} {3}", feature, currentTime.ToShortDateString(), currentTime.ToLongTimeString(), currentTime.Millisecond);
            timestart = currentTime;
            sw.Close();
            #endif
        }

        public static void EndLog(string feature)
        {
            #if DEBUG
            if(!IsoFile.DirectoryExists("Log"))
                IsoFile.CreateDirectory("Log");

            StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Log\\log_take_photo_together.log", FileMode.OpenOrCreate, IsoFile));
            DateTime currentTime = DateTime.Now;
            Debug.WriteLine("[{0}] end {1} {2} {3}", feature, currentTime.ToShortDateString(), currentTime.ToLongTimeString(), currentTime.Millisecond);
            sw.WriteLine("[{0}] end {1} {2} {3}", feature, currentTime.ToShortDateString(), currentTime.ToLongTimeString(), currentTime.Millisecond);

            TimeSpan feature_proccess = currentTime - timestart;
            Debug.WriteLine("[{0}] proccess time ms {1}", feature, feature_proccess.TotalMilliseconds);
            sw.WriteLine("[{0}] proccess time ms {1}", feature, feature_proccess.TotalMilliseconds);
            sw.Close();
            #endif
        }
    }
}
